package com.example.controller;

import com.example.common.Result;
import com.example.entity.ActivitySignup;
import com.example.entity.OrganizationActivity;
import com.example.service.ActivitySignupService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@RestController
@RequestMapping("/activitySignup")
public class ActivitySignupController {
    @Resource
    private ActivitySignupService activitySignupService;

    @PostMapping("/signup")
    public Result signup(@RequestBody ActivitySignup activitySignup) throws ParseException {
        // 不再从 session 获取用户 ID，而是直接从请求体中获取
        return activitySignupService.signup(activitySignup);
    }


    /**
     * 分页查询活动
     */
    @GetMapping("/selectMyPage")
    public Result selectPage(ActivitySignup activitySignup,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<ActivitySignup> page = activitySignupService.selectMyPage(activitySignup, pageNum, pageSize);
        return Result.success(page);
    }

    @PostMapping("/cancel/{id}")
    public Result cancelSignup(@PathVariable Long id, @RequestParam Long userId) {
        return activitySignupService.cancelSignup(id, userId);
    }
}
